<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>离职审核流程</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../../../../res/js/error.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
</head>
<body style="padding: 10px">
<h1 align="center" style="margin-bottom: 20px" id="dimissionForm">员工辞职申请</h1>
<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <input type="hidden" id="pkDimissionId" name="pkDimissionId"/>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">姓名</label>
            <div class="layui-input-inline">
                <!--<select name="personnelId" id="personnelId" lay-filter="aihao" lay-search="">
                    <option value="" selected="">请选择</option>
                </select>-->
                <input autocomplete="off" class="layui-input" lay-verify="required" disabled name="personnelName"
                       id="personnelName"
                       type="text"/>
                <input id="personnelId" type="hidden" value="personnelId"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">身份证号</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" id="personnelIdentity"
                       name="personnelIdentity" placeholder="请输入身份证号" disabled
                       type="text"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">所在部门</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled name="departmentName"
                       id="departmentName" disabled
                       type="text"/>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">入职时间</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled id="entryTime" name="entryTime"
                       placeholder="yyyy-MM-dd" disabled
                       type="text">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">申请日期</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled id="dimissionCurrentDate" lay-verify="date"
                       name="dimissionCurrentDate"
                       placeholder="yyyy-MM-dd" disabled
                       type="text">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">计划正式离职日期</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" id="dimissionTime" lay-verify="date" name="dimissionTime"
                       placeholder="yyyy-MM-dd" disabled
                       type="text">
            </div>
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">离职类型</label>
        <div class="layui-input-block">
            <input type="radio" disabled id="dimissionType0" name="dimissionType" value="0" title="试用期内离职">
            <input type="radio" disabled id="dimissionType1" name="dimissionType" value="1" title="合同期内离职">
            <input type="radio" disabled id="dimissionType2" name="dimissionType" value="2" title="合同到期">
            <input type="radio" disabled id="dimissionType3" name="dimissionType" value="3" title="其他">
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label" style="width: 135px">离职原因类型</label>
        <div class="layui-input-block" style="margin-left: 135px">
            <input type="radio" disabled id="dimissionCauseType0" name="dimissionCauseType" value="0" title="主动离职">
            <input type="radio" disabled id="dimissionCauseType1" name="dimissionCauseType" value="1" title="辞退">
            <input type="radio" disabled id="dimissionCauseType2" name="dimissionCauseType" value="2" title="其他">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">离职原因</label>
        <div class="layui-input-block">
            <input type="text" id="dimissionCause" disabled name="dimissionCause" autocomplete="off"
                   placeholder="请输入离职原因" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">对公司希望</label>
        <div class="layui-input-block">
            <input type="text" disabled name="companyExpectation" id="companyExpectation" autocomplete="off"
                   placeholder="对公司希望" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 175px">离职后部门安排交接给</label>
        <div class="layui-input-block" style="margin-left:175px">
            <select name="personnelIds" id="personnelIds" lay-filter="aihao" lay-search="">
                <option value="" selected="">请选择员工</option>
            </select>
        </div>
    </div>
    <!--<div class="layui-form-item layui-form-text">
        <label class="layui-form-label">员工离职须知</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" disabled="">
                1、试用期员工需提前3天提出申请，正式员工需要提前30天提出申请，以便部门做好充分的工作交接；
                2、提出申请期间不得传播任何负面信息，否则公司按照劳动纪律管理规定处理；
                3、离职审批后请做好离职交接工作。
            </textarea>
            <input type="checkbox" name="consent" id="consent" lay-skin="primary" title="同意上述员工离职须知">
        </div>
    </div>-->
    <hr/>
    <div class="layui-form-item layui-form-text" id="section">
        <label class="layui-form-label">主管部门审核意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" lay-verify="required" id="departmentLeadership" name="departmentLeadership"
                      class="layui-textarea">
            </textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text" id="staffing">
        <label class="layui-form-label">行政人事部审核意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" lay-verify="required" id="personnelCondition" name="personnelCondition"
                      class="layui-textarea">
            </textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <!--<div class="layui-input-block" id="flows">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>-->
        <div class="layui-input-block" id="flowTwo">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo2">通过</button>
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="不通过">
        </div>
    </div>
</form>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>流程日志</legend>
</fieldset>
<ul class="layui-timeline" id="schedule">

</ul>

<script>
    var table2;
    // 修改赋值
    let pkDimissionId = getQueryString("pkDimissionId");
    // 查看
    let show = getQueryString("show");
    let sectionPass = "OaDimissionFlowAction/sectionPass";
    let sectionNoPass = "OaDimissionFlowAction/sectionNoPass";
    let isRevision = "";
    let departmentLeadership;
    let personnelCondition;
    layui.use(['form', 'table', 'layedit', 'laydate'], function () {
        var table = layui.table
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , form = layui.form;
        // 入职日期
        laydate.render({
            elem: '#entryTime'
        });
        // 离职申请日期
        laydate.render({
            elem: '#dimissionCurrentDate'
        });
        // 正式离职日期
        laydate.render({
            elem: '#dimissionTime'
        });

        $("#pkDimissionId").val(pkDimissionId);

        let res = getAjaxById(getRootPath() + "OaDimissionFlowAction/findById/" + pkDimissionId);

        $("input[name=dimissionType][value='0']").attr("checked", res.dimissionType == 0 ? true : false); // 离职类型 试用期内离职
        $("input[name=dimissionType][value='1']").attr("checked", res.dimissionType == 1 ? true : false); // 离职类型 合同期内离职
        $("input[name=dimissionType][value='2']").attr("checked", res.dimissionType == 2 ? true : false); // 离职类型 合同到期
        $("input[name=dimissionType][value='3']").attr("checked", res.dimissionType == 3 ? true : false); // 离职类型 其他

        $("input[name=dimissionCauseType][value='0']").attr("checked", res.dimissionCauseType == 0 ? true : false); // 离职原因类型 主动离职
        $("input[name=dimissionCauseType][value='1']").attr("checked", res.dimissionCauseType == 1 ? true : false); // 离职原因类型 辞退
        $("input[name=dimissionCauseType][value='2']").attr("checked", res.dimissionCauseType == 2 ? true : false); // 离职原因类型 其他

        $("#dimissionCause").val(res.dimissionCause); // 离职原因
        $("#companyExpectation").val(res.dimissionCause); // 对公司希望
        $("#dimissionCurrentDate").val(dateFormat('yyyy-MM-dd', new Date(res.dimissionCurrentDate))); // 申请日期
        $("#dimissionTime").val(dateFormat('yyyy-MM-dd', new Date(res.dimissionTime)));//正式离职日期
        let personnelIds = res.personnelIds;
        isRevision = res.isRevision;
        departmentLeadership = res.departmentLeadership;
        personnelCondition = res.personnelCondition;
        if (res.isRevision == "D") {
            $("#staffing").remove();
        } else if (res.isRevision == "S") {
            sectionPass = "OaDimissionFlowAction/staffingPass";
            sectionNoPass = "OaDimissionFlowAction/staffingNoPass";
            $("#departmentLeadership").attr("disabled", "");
            $("#departmentLeadership").val(res.departmentLeadership);
        }


        res = getAjaxById(getRootPath() + "OaPersonnelAction/findById/" + res.personnelId);
        // 离职人员id
        $("#personnelId").val(res.data.pkPersonnelId);
        //离职人员名称
        $("#personnelName").val(res.data.personnelName);
        // 离职人员部门
        $("#departmentName").val(res.data.departmentName);
        // 离职人员身份证
        $("#personnelIdentity").val(res.data.personnelIdentity);
        if(res.data.entryTime){
            // 入职日期
            $("#entryTime").val(dateFormat('yyyy-MM-dd', new Date(res.data.entryTime)));
        }
        //查询同一个部门下所有人员
        res = getAjaxById(getRootPath() + "OaPersonnelAction/selectByDepartmentId/" + res.data.organizationId);
        //赋值人员下拉框
        $("#personnelIds").html('<option value="" selected="">请选择员工（必填）</option>');
        $.each(res.data, function (index, item) {
            $("#personnelIds").append('<option value="' + item.pkPersonnelId + '">' + item.personnelName + '</option>')
        });
        $("#personnelIds").val(personnelIds); // 交接人
        $("#personnelIds").attr("disabled", ""); // 交接人

        if (show) {
            console.info(isButton("SECTION_CHECK"));
            if(isButton("STAFFING_CHECK")){
                $("#section").attr("disabled", "");
                $("#departmentLeadership").attr("disabled", "");
                $("#departmentLeadership").val(departmentLeadership);
                $("#personnelCondition").attr("disabled", "");
                $("#personnelCondition").val(personnelCondition);
            } else if(isButton("SECTION_CHECK")){
                $("#departmentLeadership").attr("disabled", "");
                $("#departmentLeadership").val(departmentLeadership);
                $("#staffing").remove();
            }else{
                $("#staffing").remove();
                $("#section").remove();
            }
            if(!isButton("STAFFING_CHECK")){
                $("#staffing").remove();
            }else {
                $("#staffing").attr("disabled", "");
            }

            $("#flowTwo").remove();
        }

        form.render();


        //监听提交
        form.on('submit(demo2)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });*/
            if (isRevision === "S") {
                data = {
                    departmentLeadership: $("#personnelCondition").val(),
                    pkDimissionId: pkDimissionId
                };
            } else if (isRevision === "D") {
                data = {
                    departmentLeadership: $("#departmentLeadership").val(),
                    pkDimissionId: pkDimissionId
                };
            }

            const res = postAjax(getRootPath() + sectionPass, data);
            if (res === 1) {
                layer.msg('审核成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3001);
                //window.location.reload();//刷新页面
            } else if (res === 500) {
                error('500');
            } else {
                layer.msg("新增失败");
            }

            return false;
        });
        //监听审核提交不通过
        $('#demo3').on('click', function () {
            //prompt层
            layer.prompt({
                formType: 2,
                value: '',
                title: '请输入原因',
                area: ['300px', '100px']
            }, function (text, index) {
                layer.close(index);
                let data = {
                    departmentLeadership: text,
                    pkDimissionId: pkDimissionId
                };

                /*layer.msg('您最后写下了：'+text);*/
                const res = postAjax(getRootPath() + sectionNoPass, data);
                if (res === 1) {
                    layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                    setTimeout(function () {
                        formClose();
                    }, 3000);
                    setTimeout(function () {
                        parent.layui.table.reload('test');//刷新父页面
                        //window.parent.location.reload();//刷新父页面
                        const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }, 3001);
                } else if (res === 500) {
                    error('500');
                } else {
                    layer.msg("新增失败");
                }
            });

            return false;
        });

        const ress = getAjaxById(getRootPath() + "OaFlowAction/selectFlowSchedule/" + pkDimissionId);
        $("#schedule").html("");
        $.each(ress, function (index, item) {
            if (item.createdBy) {
                $("#schedule").append('<li class="layui-timeline-item">\n' +
                    '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                    '        <div class="layui-timeline-content layui-text">\n' +
                    '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                    '            <p>' + item.formReason + '</p>\n' +
                    '            <p>操作人：' + item.createdBy + '</p>\n' +
                    '        </div>\n' +
                    '    </li>')

            } else {
                $("#schedule").append('<li class="layui-timeline-item">\n' +
                    '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                    '        <div class="layui-timeline-content layui-text">\n' +
                    '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                    '            <p>' + item.formReason + '</p>\n' +
                    '        </div>\n' +
                    '    </li>')
            }
        });

    });
</script>
</body>
</html>